#ifndef _UTILEX_COND_HPP_
#define _UTILEX_COND_HPP_

#include <crt_util.h>

#ifdef __cplusplus

class CCondHandle
{
public:
	CCondHandle() {
		_cond_init(&this->m_h, WAIT_TIME_RELATIVE);
		_mutex_init(&this->m_mutex);
	}
	~CCondHandle()  {
		Close();
	}

	HRESULT Close() {

        _mutex_destroy(&this->m_mutex);
		_cond_destroy(&this->m_h);
	
		return S_OK;
	}

	HRESULT Wait() {

		_cond_wait(&this->m_h,&this->m_mutex);
		return S_OK;
	}

	HRESULT WaitTime(int sec) {

		_cond_timedwait(&this->m_h, &this->m_mutex, sec);
		return S_OK;
	}

	HRESULT Signal() {

		_cond_signal(&this->m_h);
		return S_OK;
	}

	HRESULT Broadcast() {

		_cond_broadcast(&this->m_h);
		return S_OK;
	}


public:
	_cond_t m_h;
	_mutex_t m_mutex;
};



#endif


#endif
